package com.hyd.action;

import java.util.List;
import com.base.dialect.PaginationSupport;
import com.base.dao.model.Ret;
import com.base.dao.model.Grid;
import com.hyd.dao.model.XAxis;
import com.hyd.dao.model.XAxisExample;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.commons.lang.StringUtils;
import com.base.util.JSONUtils;
import com.base.web.annotation.LoginFilter;
import org.springframework.beans.factory.annotation.Autowired;
import com.base.action.CoreController;
import com.hyd.dao.model.YAxis;
import com.hyd.dao.model.YAxisExample;
import com.hyd.service.YAxisService;

/**
@author sun
*/
@RequestMapping("yAxis")
@Controller
@LoginFilter
public class YAxisController extends CoreController{

    @Autowired
    private YAxisService yAxisService;

    @RequestMapping("/list")
	@ResponseBody
    public String list(Integer page, Integer rows){
    	PaginationSupport.byPage(page, rows);
    	YAxisExample example = new YAxisExample();

    	List<YAxis> list = yAxisService.selectByExample(example);
      	return page(list);
    }

    @RequestMapping("/save")
	@ResponseBody
    public String save(YAxis yAxis){
    	if (yAxis.getId() == null){
    		yAxisService.insert(yAxis);
    	}else{
    		yAxisService.updateByPrimaryKeySelective(yAxis);
    	}
       	return ok();
    }

    @RequestMapping("/findById")
	@ResponseBody
    public String find(Integer id){
    	YAxis yAxis = yAxisService.selectByPrimaryKey(id);
       	return ok(yAxis);
    }

    @RequestMapping("/del")
	@ResponseBody
    public String del(String id){
    	String[] ids = id.split(",");
    	for (String str : ids){
    		yAxisService.deleteByPrimaryKey(Integer.parseInt(str));
    	}
       	return ok();
    }

	@RequestMapping("/getYAxisList")
	@ResponseBody
	public String getXAxisList(Integer chemicalTypeId){
		YAxisExample example = new YAxisExample();
		example.createCriteria().andChemicalTypeIdEqualTo(chemicalTypeId);
		List<YAxis> list = yAxisService.selectByExample(example);
		return ok(list.get(0));
	}


}